package com.mgq.algorithm.array;

public class GetMax {
    public static void main(String[] args) {
        int[] array = {1,65,34,34,5,3,223,5768,53,22,3};
        int process = process(array, 0, array.length - 1);
        System.out.println(process);
    }

    /**
     * 求arr[L...R]中的最大值
     * 使用递归+二分
     *                                  P(0,5)
     *                                    /    \
     *                                 p(0,2)   p(3,5)
     *                                 /   \       \
     *                               p(0,1) p(1,2)  p(3,4) p(4,5)
     *                               ---------
     * @param array
     * @param L
     * @param R
     * @return
     */
    public static int  process(int[] array,int L,int R) {
        if (L == R) {
            return array[L];
        }
        int mid=L+((R-L)>>1);
        int leftMax = process(array, L, mid);
        int rightMax = process(array, mid + 1, R);
        return Math.max(leftMax, rightMax);
    }
}
